<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:79:"D:\www\photo_albums_bless\public_html/../application/admin\view\image\edit.html";i:1544068620;s:69:"D:\www\photo_albums_bless\application\admin\view\lib\common_list.html";i:1543818465;}*/ ?>
<!DOCTYPE html>
<html>


<!-- Mirrored from www.zi-han.net/theme/hplus/ by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:16:41 GMT -->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <title></title>

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/plugins/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/sys/css/style.min.css">
    <link rel="stylesheet" href="/static/plugins/bootstrap-table/bootstrap-table.css">
    <!--<link rel="stylesheet" href="/static/plugins/dataTables/dataTables.bootstrap.css">-->
    <link rel="stylesheet" href="/static/plugins/layer/skin/layer.css">
    <link rel="stylesheet" href="/static/plugins/layer/skin/layer.ext.css">
    <link rel="stylesheet" href="/static/plugins/layer/laydate/need/laydate.css">
    <link rel="stylesheet" href="/static/plugins/layer/laydate/skins/default/laydate.css">
    
    <script src="/static/plugins/jquery-1.12.4/jquery-1.12.4.min.js"></script>
    <script src="/static/plugins/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="/static/plugins/layer/layer.min.js"></script>
    <script src="/static/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/static/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="/static/plugins/layer/laydate/laydate.js"></script>

    <style>
        .text-red{color:red;}
        .text-green{color:#17bb46;}
        .text-orange{color:orange;}
        .text-yellow{color:#c7cd2f;}
        .text-blue{color:#0bb8c8;}
        .fixed-table-toolbar .bars, .fixed-table-toolbar .columns, .fixed-table-toolbar .search{margin-top:-45px;}
        .th-inner{color:#555;}
    </style>
    
<link rel="stylesheet" type="text/css" href="/static/sys/css/common.css" />
<link rel="stylesheet" type="text/css" href="/static/plugins/select2/css/select2.css" />
<link rel="stylesheet" type="text/css" href="/static/sys/css/skin_0.css" />
<style>
    .upfile i{padding-right:3px !important;}
    .file{ position:absolute;right:0;top:0;width:100px;height:100px;opacity:0; ilter:alpha(opacity=0);cursor:pointer;margin-bottom: 0px;margin-right: 0px; }
</style>

</head>

<body class="gray-bg">
    
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" id="fmNew" class="form-horizontal" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="name" value="<?php echo $data['name']; ?>">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片地址：</label>
                            <div class="col-sm-6">
                                <input type="text" name="url" class="form-control" value="<?php echo $data['url']; ?>">
                            </div>
                            <div class="col-sm-1">
                                <span id="btn-upfile1" class="btn btn-warning btn-sm" style="margin-bottom:0;padding:6px 8px;">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 选择上传<input type="hidden" name="image_cover1" id="image_cover1" /><input id="file" class="file" type="file" name="pic" suffix="cover1" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_cover1" style="height:34px;float: right;">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片类型：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="cate_name" id="cate_name" onchange="categoryValue()">
                                    <option>请选择图片类型.......</option>
                                    <?php if(is_array($category_list) || $category_list instanceof \think\Collection || $category_list instanceof \think\Paginator): $i = 0; $__LIST__ = $category_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $v['name']; ?>" cate_id="<?php echo $v['id']; ?>" <?php if($v['name'] == $data['cate_name']): ?> selected <?php endif; ?>><?php echo $v['name']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div id="hidden_input">
                            <input type="hidden" name="cate_id" id="cate_id" value="<?php echo $data['cate_id']; ?>"/>
                            <input type="hidden" name="id" id="id" value="<?php echo $data['id']; ?>"/>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-12 col-sm-offset-5">
                                <button class="btn btn-primary" id="ok" type="button">提交</button>
                                <button class="btn btn-white" id="cancel" type="button">取消</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
    
<script>
    $(document).ready(function () {
        $("#ok").bind("click", Save);
        $("#cancel").bind("click", function () {
            parent.layer.close(parent.layer_edit_index);
        });

        /**
         * 保存内容
         */
        function Save() {
            var name = $.trim($("input[name=name]").val());
            if (name.length == 0) {
                layer.tips('请输入图片名称', 'input[name=name]', {tips: [2, '#78BA32']});
                return false;
            }

            var url = $.trim($("input[name=url]").val());
            var image_cover1 = $.trim($("input[name=image_cover1]").val());
            if (url.length == 0 && image_cover1.length == 0) {
                layer.tips('请输入图片外链地址或选择上传', 'input[name=url]', {tips: [2, '#78BA32']});
                return false;
            }

            var load_index = layer.load(0, { shade: false });
            $.ajax({
                type: 'POST',
                url: "<?php echo url('image/edit'); ?>?id=<?php echo $data['id']; ?>",
                data: $("#fmNew").serialize(),
                dataType: 'json',
                success: function (data) {
                    layer.close(load_index);
                    if (data.code == 0) {
                        layer.alert('修改成功', function () {
                            parent.refreshtb();
                            parent.layer.close(parent.layer_edit_index);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        }

        // 上传图片
        var fileEls = document.getElementById('file');
        var fullBase64;
        var base64;
        $("#file").change(function (evt) {
            $("input[name='cover_url']").val('');
            if (!window.FileReader) return;
            var files = evt.target.files;
            var suffix = $(this).attr("suffix");

            for (var i = 0, f; f = files[i]; i++) {
                if (!f.type.match('image.*')) {
                    continue;
                }
                var imgagetype = files[i].type;
                var reader = new FileReader();
                reader.onload = (function (theFile) {
                    return function (e) {
                        fullBase64 = e.target.result;
                        appendFile(fullBase64, imgagetype, suffix);
                    };
                })(f);
                reader.readAsDataURL(f);
                $("input[name='url']").val('');
            }
        });

        function appendFile(entry, imgagetype, suffix) {
            var img = new Image();
            img.src = entry;

            img.onload = function () {
                var that = this;
                /*图片不压缩*/
                var w = that.width, h = that.height;

                //生成canvas
                var canvas = document.createElement('canvas');
                var ctx = canvas.getContext('2d');
                $(canvas).attr({width: w, height: h});
                ctx.drawImage(that, 0, 0, w, h);
                base64 = canvas.toDataURL(imgagetype, 1);
                document.getElementById('previewImg_' + suffix).src = base64;
                document.getElementById('image_' + suffix).value = base64;
            }
        }
        $('#cate_name').select2();

    });

    function categoryValue() {
        var cate_id = $("#cate_name").children('option:selected').attr('cate_id');
        $('#cate_id').val(cate_id);
    }
</script>

<!-- Mirrored from www.zi-han.net/theme/hplus/ by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:17:11 GMT -->
</html>
